﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<VTLive.Models.Station>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Details
</asp:Content>

    
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="station_info">
    <h2>
        Details</h2>

        <div>
            Name:
            <%= Html.Encode(ViewData["station_name"]) %>
        </div>
        <div>
            Description:
            <%= Html.Encode(ViewData["station_description"]) %>
        </div>
        <div>
            Owner:
            <%= Html.Encode(ViewData["station_owner"]) %>
        </div>
        <div>
            VideoID:
        </div>
        
        <div id="station_schedule">
        <%if (ViewData["station_schedule"] != null)
          { %>
        <ul>
            <%foreach (VTLive.Models.Video vid in ViewData["station_schedule"] as IQueryable<VTLive.Models.Video>)
              {%>
            
            <li> <%= Html.Encode(vid.Name)%></li>
            
            <% } %>
            
        </ul>
        <%}
          else
          { %>
            <p>The Station is not broadcasting right now.</p>
        <%} %>
        </div>
        <div id="station_video">
        <% if (ViewData["station_video_string"] != null)
           { %>
            <div id="ytapiplayer"></div>
       <%=Html.Encode(ViewData["station_video_string"]) %>
            
       <script  type="text/javascript" src="../../Scripts/swfobject.js"></script>
                <script type="text/javascript">
                    var VidString = "<%= Html.Encode(ViewData["station_video_string"])%>";
                    var VidArray = VidString.split("~");
	                var VidIndex = 0;
                    var ytplayer = null;
                    var params = { allowScriptAccess: "always" };
                    var atts = { id: "myytplayer" };

                    swfobject.embedSWF("http://www.youtube.com/v/" + VidArray[VidIndex] + "?enablejsapi=1&rel=0&playerapiid=ytplayer&autoplay=1", "ytapiplayer", "425", "356", "8", null, null, params, atts);

                    function onYouTubePlayerReady(playerId) 
                    {
                        ytplayer = document.getElementById("myytplayer");
                        ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
                        ytplayer.addEventListener("onError", "onPlayerError");
                        ytplayer.playVideo();
                    }
                    
                    function onPlayerError(errorCode) 
                    {
                        if(errorCode == 2)
                        {   alert("Invalid Video ID. Please press play to continue viewing.")
                            VidIndex = VidIndex + 1;
                            ytplayer.loadVideoById(VidArray[VidIndex], 0, "medium"); 
                            
                        }
                        ytplayer.playVideo();
                    }
                    

                    function onytplayerStateChange(newState) 
                    {
                        if (newState == 0) 
                        {
                            VidIndex = VidIndex + 1;
                            ytplayer.loadVideoById(VidArray[VidIndex], 0, "medium");
                        }
                    }
                </script>

                <script type="text/javascript">

                    ytplayer.playVideo();

                </script>
                
                <h2><a href="javascript:ytplayer.playVideo()">Play</a></h2> 
                <h2><a href="javascript:ytplayer.mute()">Mute</a></h2>
                    
            <% }
           else
           {%>
            
                <img alt="Afsakið Hlé" src="../../Content/afsakidhle.jpg" width="425" height="365"/>
        <% } %>
        </div>
    </div>
</asp:Content>
